<template>
  <div class="nav">
    <div class="nav_left">
      <span>TML智能会议助手</span>
    </div>
    <div class="nav_right">
      <router-link to="/home/main" :class="{ 'active': isActive('/home/main') }">
        <!-- 使用 t('head.chatListHome') 获取翻译文本 -->
        <span>{{ t('head.chatListHome') }}</span>
      </router-link>
      <router-link to="/home/recomment" :class="{ 'active': isActive('/home/recomment') }">
        <!-- 使用 t('head.chatListRecommend') 获取翻译文本 -->
        <span>{{ t('head.chatListRecommend') }}</span>
      </router-link>
      <router-link to="/home/talk" :class="{ 'active': isActive('/home/talk') }">
        <!-- 使用 t('head.chatListForum') 获取翻译文本 -->
        <span>{{ t('head.chatListForum') }}</span>
      </router-link>
      <router-link to="/home/myConf" :class="{ 'active': isActive('/home/myConf') }">
        <!-- 使用 t('head.chatListMyConferences') 获取翻译文本 -->
        <span>{{ t('head.chatListMyConferences') }}</span>
      </router-link>
      <!-- 黑暗主题切换 -->
      <!-- <el-form-item >
            <el-switch  class="mt-2"
    style="margin-left: 24px;margin-top: 20px"
    inline-prompt
    :active-icon="MoonNight"
    :inactive-icon="Sunny" v-model="dark"
    @change="changeTheme"
     >
            </el-switch>
      </el-form-item> -->

      <!-- 根据有无token进行判断 -->
      <span v-if="token" class="logout" @click="logout">
        <!-- 使用 t('head.chatListExit') 获取翻译文本 -->
        {{ t('head.chatListExit') }}
      </span>
      <router-link v-else to="/login" class="login-register">
        <span>登录 | 注册</span>
      </router-link>
      <div class="demo-color-block">
        <span class="demonstration">主题</span>
        <el-color-picker v-model="themeColor" @change="changeTheme(themeColor)"/>
      </div>
    </div>
  </div>
  <div class="body">
    <router-view></router-view>
  </div>
  <el-backtop :right="100" :bottom="100" />
</template>

<script setup lang="ts">
import { useRoute,useRouter } from 'vue-router';
import { ref,onMounted } from 'vue';
import {useTheme} from '../../hooks/useTheme'
import {t} from '../../locales/index'
const {changeTheme}=useTheme()
const themeColor = ref()

const route = useRoute();
const router=useRouter()
const token=ref<string|null>(null);

onMounted(()=>{
  token.value=localStorage.getItem('token')
})

const isActive = (path:string) => {
  return route.path.startsWith(path);
};
//退出登录
const logout=()=>{
  localStorage.removeItem('token')
  token.value=null
  router.push('/')

}

</script>

<style lang="scss" scoped>
.nav {
  width: 100%;
  height: 80px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  position: fixed;
  z-index: 3;
  background-color: #ffffff;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);

  .nav_left {
    margin-left: 60px;

    span {
      font-size: 2rem;
      font-weight: 600;
      background-image: linear-gradient(90deg, #044bb5, #1ec191);
      background-clip: text;
      -webkit-background-clip: text;
      color: transparent;
    }
  }

  .nav_right {
    margin-right: 60px;
    display: flex;
    align-items: center;

    a {
      text-decoration: none;
      font-size: 1.1rem;
      color: #333;
      padding: 10px 20px;
      border-radius: 20px;
      transition: all 0.3s ease;
      margin-left: 20px;

      &:hover, &.active {
        background: linear-gradient(to right, #1e7acf, #2db1ba);
        color: #ffffff;
      }
    }

    .login-register, .logout {
      height: 1rem;
     display: flex;
      border: 1px solid #1e7acf;
       align-items: center;
       color: #3f3f3f7d;
       cursor: pointer;
      &:hover {
        background: #ffffff;
        color: #1e7acf;
      }
    }
    .logout {
      text-decoration: none;
      font-size: 1.1rem;
      color: #333;
      padding: 10px 20px;
      border-radius: 20px;
      transition: all 0.3s ease;
      margin-left: 20px;
      
    }
  }
}

.body {
  padding-top: 80px;
}

// 颜色选择器样式
.demo-color-block {
  display: flex;
  align-items: center;
  color: #333;
  margin-top: 1px;
  margin-left: 10px;
  font-size: 1.1rem;
}
.demo-color-block .demonstration {
  color: #333;
  margin-right: 4px;
}
</style>